package com.eric.rabbitmq.simpe;


import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.nio.charset.StandardCharsets;

public class Producer {
    //队列名称
    public static  final  String QUEUE_NAME = "hello";
    //发消息
    public static void main(String[] args) throws Exception{
        //创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //工厂IP 连接mq队列
        factory.setHost("172.100.2.13");
        //用户名和密码
        factory.setUsername("admin");
        factory.setPassword("admin");
        //创建连接
        Connection connection = factory.newConnection();
        //获取信道
        Channel channel = connection.createChannel();
        //生产队列
        channel.queueDeclare(QUEUE_NAME, false,false,false,null);
        //发消息
        String msg = "Hello,eric";
        channel.basicPublish("",QUEUE_NAME,null,msg.getBytes());
        System.out.println("消息发送完毕");

    }
}
